package com.googlecode.dgwt.client.dijit.view.render.base;

import com.googlecode.dgwt.client.dijit.View;
import com.googlecode.dgwt.client.dijit.Widget;
import com.googlecode.dgwt.client.dijit.base.widget.WidgetEngine;
import com.googlecode.dgwt.client.dojo.exception.DojoRuntimeException;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public abstract class ViewRenderBase implements ViewRender {

    private final View view;
    
    public ViewRenderBase(View view){
        this.view = view;
    }
    
    @Override
    public View getView() {
        return view;
    }
    
    public Widget getWidget(){
        return view.getWidget();
    }
    
    protected WidgetEngine getEngine(){
        return WidgetEngine.get(view.getWidget());
    }
    
    @Override
    public final void buildRendering() {
        if (getEngine().isReady()){
            throw new DojoRuntimeException(this, "the target widget was already rendered");
        }
        doBuildRendering();
    }

    protected abstract void doBuildRendering();

}
